package com.pys.menu;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

public class MenuChildItem implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private String title;
	private String type;
	private String link;
	private String showNewIcon;
	private String newIconExpiresAt;
	private String openAsPopUp;
	private String popUpWidth;
	private String popUpHeight;

	public MenuChildItem(String title, String type, String link) {
		super();
		this.title = title;
		this.type = type;
		this.link = link;
	}

	private String capIslem;

	private boolean isNewIcon;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getShowNewIcon() {
		return showNewIcon;
	}

	public void setShowNewIcon(String showNewIcon) {
		this.showNewIcon = showNewIcon;
		this.isNewIcon = checkNewIcon();
	}

	public String getNewIconExpiresAt() {
		return newIconExpiresAt;
	}

	public void setNewIconExpiresAt(String newIconExpiresAt) {
		this.newIconExpiresAt = newIconExpiresAt;
		this.isNewIcon = checkNewIcon();
	}

	public boolean checkNewIcon() {
		if (getShowNewIcon() != null && getShowNewIcon().equals("true")) {
			try {
				if (StringUtils.isBlank(getNewIconExpiresAt()))
					return true;
				Date expiresAt = new SimpleDateFormat("dd/MM/yyyy")
						.parse(getNewIconExpiresAt());
				if (expiresAt.compareTo(new Date()) > 0) {
					return true;
				} else
					return false;
			} catch (ParseException e) {
				e.printStackTrace();
				// Logger.error(this.getClass(), "Date parse Exception", e);
				// ignore exception
				return true;
			}
		} else
			return false;

	}

	public boolean isNewIcon() {
		return this.isNewIcon;
	}

	public String getOpenAsPopUp() {
		return openAsPopUp;
	}

	public void setOpenAsPopUp(String openAsPopUp) {
		this.openAsPopUp = openAsPopUp;
	}

	public String getPopUpWidth() {
		return popUpWidth;
	}

	public void setPopUpWidth(String popUpWidth) {
		this.popUpWidth = popUpWidth;
	}

	public String getPopUpHeight() {
		return popUpHeight;
	}

	public void setPopUpHeight(String popUpHeight) {
		this.popUpHeight = popUpHeight;
	}

	public String getCapIslem() {
		return capIslem;
	}

	public void setCapIslem(String capIslem) {
		this.capIslem = capIslem;
	}
}
